/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.gui.security;

import it.polimi.registration.business.security.boundary.UsersEventManager;
import it.polimi.registration.business.security.boundary.UsersManager;
import it.polimi.registration.business.security.entity.Event;
import it.polimi.registration.business.security.entity.Users;
import it.polimi.registration.business.security.entity.UsersEvent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

/**
 *
 * @author Luca
 */
@Named
@SessionScoped
public class UsersEventBean implements Serializable{
    
    private UsersEvent usersEvent;
    
    @EJB
    private UsersEventManager uem;
    
    @EJB
    private UsersManager um;
    
    private String invitedEmail;


    
    /**
     * @return the usersEvent
     */
    public UsersEvent getUsersEvent() {
        if (usersEvent == null) {
            usersEvent = new UsersEvent();
        }
        return usersEvent;
    }

    /**
     * @param usersEvent the usersEvent to set
     */
    public void setUsersEvent(UsersEvent usersEvent) {
        this.usersEvent = usersEvent;
    }

    public void addUsersEvent() { 
        System.out.println("Saving Event: "+usersEvent);
        uem.save(usersEvent);
    }
    
  
    
    public String acceptInvitation(Event event){
        uem.accept(event, um.getLoggedUsers());
        return "/home?faces-redirect=true";
    }
    
    public String declineInvitation(Event event){
        uem.decline(event, um.getLoggedUsers());
        return "/home?faces-redirect=true";
    }

    /**
     * @return the invitedEmail
     */
    public String getInvitedEmail() {
        return invitedEmail;
    }

    /**
     * @param invitedEmail the invitedEmail to set
     */
    public void setInvitedEmail(String invitedEmail) {
        this.invitedEmail = invitedEmail;
    }
    
}
